#ifndef _IM_SERVER_UID_SOCK_CONN_MAP_
#define _IM_SERVER_UID_SOCK_CONN_MAP_

#include <string>
#include <boost/unordered_map.hpp>
#include <boost/thread.hpp>
#include "sock_connection.h"
#include "base/logging.h"
#include "base/singleton.h"
#include <vector>

namespace imserver {

extern std::string g_shard_path;

class UidSockConnMap : public base::Singleton<UidSockConnMap> {
 public:
  void add(int64_t uid, SockConnectionPtr conn);
  void remove(int64_t uid);
  bool get(int64_t uid, SockConnectionPtr& conn);

  const static int BUCKET_COUNT = 20;
 private:
  friend class base::Singleton<UidSockConnMap>;

  UidSockConnMap() {
    for (int i = 0; i < BUCKET_COUNT; ++i) {
      uid_conn_maps_.push_back(MapType());
    }
  }

  typedef boost::unordered_map<int64_t, SockConnectionPtr> MapType;
  std::vector<MapType> uid_conn_maps_;
  boost::mutex mutexies[BUCKET_COUNT];
};

}

#endif // _IM_SERVER_UID_SOCK_CONN_MAP_

